home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 0411.ZIP / TGIMAGE.C < prev    next >
Text File  |  1985-10-04  |  6KB  |  259 lines

  1. /*
  2.  * Program to accept from the command line the mnemonic - up to 2
  3.  * chars - of the micro in use.
  4.  *
  5.  * This string is then married with the system date in ddmmyy format to
  6.  * produce an 8 character string which is the file name into which or
  7.  * from which an image of the hard disk will be copied/restored.
  8.  *
  9.  */
  10. #include "stdio.h"
  11. main(argc,argv)
  12.     int argc;
  13.     char *argv[];
  14.     {
  15.     int  c,
  16.      cntr,
  17.      dmm,
  18.      ddd,
  19.      dyy,
  20.      outfile;
  21.     char date[9],
  22.      month[4],
  23.      fr[3],
  24.      to[3],
  25.      temp,
  26.      sysid[3],
  27.      datfile[12],
  28.      errmsg[80],
  29.      cmd[27];
  30.     /*
  31.      * Set the name of the file to contain the image commands.
  32.      */
  33.     strcpy(datfile,"TGIMAGE.DAT");
  34.     /*
  35.      * Check for a request for syntax information.
  36.      */
  37.     if (argv[1][0] == '?')
  38.     {
  39.     puts("\n");
  40.     puts("Syntax: TGIMAGE <machine sysid> <from id> <to id> [<date>]\n");
  41.     puts("where   <machine sysid> is a string of up to 2 chars\n");
  42.     puts("        <from id>       is a device id (eg c: or 0:)\n");
  43.     puts("        <to id>         is a device id (eg 0: or c:)\n");
  44.     puts("        <date>          is a date in ddmmyy format\n");
  45.     puts("                        NB if this parameter is not\n");
  46.     puts("                        supplied, today's date is used\n");
  47.     puts("\n");
  48.     puts("These values are manipulated to produce a TEX command\n");
  49.     puts("such that an IMAGE from the <from id> will be made\n");
  50.     puts("to the <to id> using a filename of format \n");
  51.     puts("            <machine sysid><date>.IMG\n");
  52.     unlink(datfile);
  53.     exit(0);
  54.     }
  55.     /*
  56.      * Check for a request for version information.
  57.      */
  58.     if (argv[1][0] == '#')
  59.     {
  60.     puts("\n");
  61.     puts("PROGRAM: TGIMAGE\n");
  62.     puts("Author:  Peter Townsend\n");
  63.     puts("Date:    04Oct85\n");
  64.     puts("Version: 1.0\n");
  65.     unlink(datfile);
  66.     exit(0);
  67.     }
  68.     if ((outfile = creat(datfile)) == -1)
  69.     {
  70.     strcpy(errmsg,"Cannot create output file");
  71.     tgexit(errmsg,outfile,datfile);
  72.     }
  73.     /*
  74.      * Check number and value of parameters
  75.      */
  76.     if (argc == 1)
  77.     {
  78.     strcpy(errmsg,"System mnemonic ommitted from command line.");
  79.     tgexit(errmsg,outfile,datfile);
  80.     }
  81.     if (!isalnum(argv[1][0]))
  82.     {
  83.     strcpy(errmsg,"Sorry...mnemonic characters must be alphanumeric");
  84.     tgexit(errmsg,outfile,datfile);
  85.     }
  86.     if (strlen(argv[1]) > 1)
  87.     {
  88.     if (!isalnum(argv[1][1]))
  89.         {
  90.         strcpy(errmsg,"Sorry...mnemonic characters must be alphanumeric");
  91.         tgexit(errmsg,outfile,datfile);
  92.         }
  93.     }
  94.     if (argc == 2)
  95.     {
  96.     strcpy(errmsg,"FROM drive ommitted from command line");
  97.     tgexit(errmsg,outfile,datfile);
  98.     }
  99.     if (!isalnum(argv[2][0]))
  100.     {
  101.     strcpy(errmsg,"Invalid FROM specification");
  102.     tgexit(errmsg,outfile,datfile);
  103.     }
  104.     if (strlen(argv[2]) > 1)
  105.     {
  106.     if (argv[2][1] != ':')
  107.         {
  108.         strcpy(errmsg,"Invalid FROM specification");
  109.         tgexit(errmsg,outfile,datfile);
  110.         }
  111.     }
  112.     sysid[0] = argv[1][0];
  113.     if (strlen(argv[1]) > 1)
  114.     {
  115.     sysid[1] = argv[1][1];
  116.     }
  117.     else
  118.     {
  119.     sysid[1] = 'x';
  120.     }
  121.     sysid[2] = '\0';
  122.     fr[0] = argv[2][0];
  123.     fr[1] = ':';
  124.     fr[2] = '\0';
  125.     if (argc == 3)
  126.     {
  127.     strcpy(errmsg,"TO drive ommitted from command line");
  128.     tgexit(errmsg,outfile,datfile);
  129.     }
  130.     if (!isalnum(argv[3][0]))
  131.     {
  132.     strcpy(errmsg,"Invalid TO specification");
  133.     tgexit(errmsg,outfile,datfile);
  134.     }
  135.     if (strlen(argv[3]) > 1)
  136.     {
  137.     if (argv[3][1] != ':')
  138.         {
  139.         strcpy(errmsg,"Invalid TO specification");
  140.         tgexit(errmsg,outfile,datfile);
  141.         }
  142.     }
  143.     to[0] = argv[3][0];
  144.     to[1] = ':';
  145.     to[2] = '\0';
  146.     if (isdigit(fr[0]))
  147.     {
  148.     if (isdigit(to[0]))
  149.         {
  150.         strcpy(errmsg,"Cannot image FROM tape TO tape");
  151.         tgexit(errmsg,outfile,datfile);
  152.         }
  153.     else
  154.         {
  155.         if (((tolower(to[0]) - 'a') < 0) || ((tolower(to[0]) - 'p') > 0))
  156.         {
  157.         strcpy(errmsg,"Invalid disk id");
  158.         tgexit(errmsg,outfile,datfile);
  159.         }
  160.         }
  161.     if (fr[0] > '5')
  162.         {
  163.         strcpy(errmsg,"Invalid tape no");
  164.         tgexit(errmsg,outfile,datfile);
  165.         }
  166.     }
  167.     if (isalpha(fr[0]))
  168.     {
  169.     if (isalpha(to[0]))
  170.         {
  171.         strcpy(errmsg,"Cannot image FROM disk TO disk");
  172.         tgexit(errmsg,outfile,datfile);
  173.         }
  174.     else
  175.         {
  176.         if (to[0] > '5')
  177.         {
  178.         strcpy(errmsg,"Invalid tape no");
  179.         tgexit(errmsg,outfile,datfile);
  180.         }
  181.         }
  182.     if (((tolower(fr[0]) - 'a') < 0) || ((tolower(fr[0]) - 'p') > 0))
  183.         {
  184.         strcpy(errmsg,"Invalid disk id");
  185.         tgexit(errmsg,outfile,datfile);
  186.         }
  187.     }
  188.     /*
  189.      * If the date has been ommitted from the command line,
  190.      * use today's date.
  191.      */
  192.     if (argc < 5)
  193.     {
  194.     dates(date);
  195.     sscanf(date,"%2d %c %2d %c %2d",&dmm,&temp,&ddd,&temp,&dyy);
  196.     }
  197.     else
  198.     {
  199.     if (strlen(argv[4]) < 6)
  200.         {
  201.         strcpy(errmsg,"Invalid date value");
  202.         tgexit(errmsg,outfile,datfile);
  203.         }
  204.     for(cntr=0;cntr<6;cntr++)
  205.         {
  206.         if (!isdigit(argv[4][cntr]))
  207.         {
  208.         strcpy(errmsg,"Invalid date value");
  209.         tgexit(errmsg,outfile,datfile);
  210.         }
  211.         }
  212.     ddd = (atoi(argv[4][0])*10) + atoi(argv[4][1]);
  213.     dmm = (atoi(argv[4][2])*10) + atoi(argv[4][3]);
  214.     dyy = (atoi(argv[4][4])*10) + atoi(argv[4][5]);
  215.     }
  216.     /*
  217.      * Form the values into the TEX command string.
  218.      */
  219.     if (isdigit(fr[0]))
  220.     {
  221.     sprintf(cmd,"image %2s%2s%2d%2d%2d.img %2s!!y",fr,sysid,ddd,dmm,dyy,to);
  222.     /*
  223.      * Check that the date does not include blanks in place of zeroes.
  224.      */
  225.     for(cntr=10;cntr<16;cntr++)
  226.         {
  227.         if (cmd[cntr] == ' ')
  228.         {
  229.         cmd[cntr] = '0';
  230.         }
  231.         }
  232.     }
  233.     else
  234.     {
  235.     sprintf(cmd,"image %2s %2s%2s%2d%2d%2d.img!!y",fr,to,sysid,ddd,dmm,dyy);
  236.     /*
  237.      * Check that the date does not include blanks in place of zeroes.
  238.      */
  239.     for(cntr=13;cntr<19;cntr++)
  240.         {
  241.         if (cmd[cntr] == ' ')
  242.         {
  243.         cmd[cntr] = '0';
  244.         }
  245.         }
  246.     }
  247.     /*
  248.      * 3rd last character is a CR, to have the command input to TEX.
  249.      */
  250.     cmd[23] = 0xd;
  251.     /*
  252.      * 2nd last character is a ^C, to break out of TEX.
  253.      */
  254.     cmd[24] = 0x3;
  255.     fprintf(outfile,"%24s",cmd);
  256.     fclose(outfile);
  257.     exit(0);
  258.     }
  259.